﻿package mortal.game.net.command.pet
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import extend.language.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.mvc.core.*;

    public class NewPetCommand extends BroadCastCall
    {

        public function NewPetCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_2:SSeqAttributeUpdate = null;
            var _loc_3:SPetSkillUpdate = null;
            super.call(param1);
            switch(param1.messageHead.command)
            {
                case EGateCommand._ECmdGatePet2Info:
                {
                    _cache.newPet.pet = param1.messageBase as SPublicPet2;
                    break;
                }
                case EGateCommand._ECmdGatePet2Update:
                {
                    _loc_2 = param1.messageBase as SSeqAttributeUpdate;
                    this.updateAttributes(_loc_2);
                    NetDispatcher.dispatchCmd(ServerCommand.NewPetAttributeUpdate, null);
                    break;
                }
                case EGateCommand._ECmdGatePet2SkillUpdate:
                {
                    break;
                }
                case EGateCommand._ECmdGatePet2SkillWarehouse:
                {
                    break;
                }
                case EGateCommand._ECmdGatePetSkillUpdate:
                {
                    _loc_3 = param1.messageBase as SPetSkillUpdate;
                    this.updateSkill(_loc_3);
                    NetDispatcher.dispatchCmd(ServerCommand.NewPetAttributeUpdate, null);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function updateAttributes(param1:SSeqAttributeUpdate) : void
        {
            var _loc_2:SPublicPet2 = null;
            var _loc_3:SAttributeUpdate = null;
            var _loc_4:Array = null;
            var _loc_5:EntityInfo = null;
            var _loc_6:int = 0;
            var _loc_7:Boolean = false;
            _loc_2 = _cache.newPet.pet;
            for each (_loc_3 in param1.updates)
            {
                
                _loc_4 = _loc_3.valueStr.split("#");
                switch(_loc_3.attribute.value())
                {
                    case EEntityAttribute._EAttributePet2State:
                    {
                        _loc_2.state = _loc_3.value;
                        break;
                    }
                    case EEntityAttribute._EAttributePet2ShapeCardStatus:
                    {
                        _loc_2.shapeCardStatus = _loc_3.value;
                        break;
                    }
                    case EEntityAttribute._EAttributePetName:
                    case EEntityAttribute._EAttributePet2Name:
                    {
                        _loc_2.name = _loc_4[0];
                        _loc_5 = _cache.entity.getSelfPet();
                        if (_loc_5)
                        {
                            _loc_5.updateName(_loc_4[0]);
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributePet2Bless:
                    {
                        _loc_6 = _loc_3.value - _loc_2.bless;
                        if (_loc_6 > 0)
                        {
                            MsgManager.showMouseMsg(Language.getStringByParam(20518, _loc_6), MsgRollTipsType.msgRollTips2);
                        }
                        if (_cache.newPet.petConfig.blessClear && _loc_2.bless == 0 && _loc_3.value > 0)
                        {
                            _loc_2.blessExpiredDt = new Date(ClockManager.instance.nowDate.time + ClockManager.instance.DayTime);
                        }
                        _loc_2.bless = _loc_3.value;
                        if (_loc_6 > 0)
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.BestPetUpdate, null);
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributePet2AdvanceNum:
                    {
                        _loc_2.advanceNum = _loc_3.value;
                        break;
                    }
                    case EEntityAttribute._EAttributePet2Code:
                    {
                        if (_loc_2.code != _loc_3.value)
                        {
                            _loc_7 = true;
                        }
                        _loc_2.code = _loc_3.value;
                        if (_loc_7)
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.PetAdvanceBack, false);
                            NetDispatcher.dispatchCmd(ServerCommand.PetAdvanceSucceed, null);
                            NetDispatcher.dispatchCmd(ServerCommand.BestPetUpdate, null);
                        }
                        break;
                    }
                    case EEntityAttribute._EAttributePet2Return:
                    {
                        _loc_2.advanceReturn = _loc_3.value;
                        break;
                    }
                    case EEntityAttribute._EAttributePet2SharpCode:
                    {
                        _loc_2.sharpId = _loc_3.value;
                        NetDispatcher.dispatchCmd(ServerCommand.PetSharpChangeCode, null);
                        break;
                    }
                    case EEntityAttribute._EAttributePet2CurrentGrowthNum:
                    {
                        _loc_2.totalGrowthNum = _loc_3.value;
                        break;
                    }
                    case EEntityAttribute._EAttributePet2CurrentTalentNum:
                    {
                        _loc_2.totalTalentNum = _loc_3.value;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        private function updateSkill(param1:SPetSkillUpdate) : void
        {
            switch(param1.op)
            {
                case ESkillUpdateType._ESkillUpdateTypeAdd:
                case ESkillUpdateType._ESkillUpdateTypeUpdate:
                case ESkillUpdateType._ESkillUpdateTypeUpgrade:
                {
                    _cache.newPet.pet.skillIds[param1.skill.pos] = param1.skill.skillId;
                    break;
                }
                case ESkillUpdateType._ESkillUpdateTypeRemove:
                {
                    _cache.newPet.pet.skillIds[param1.skill.pos] = null;
                    delete _cache.newPet.pet.skillIds[param1.skill.pos];
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
